000100******************************************************************
000200*PROGRAM : Instructor ISAM build                                 *
000300*AUTHOR  : H. James Vo                                           *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. INST-B.

      *-----------------------------------------------------------------
000700 ENVIRONMENT DIVISION.
000800     SELECT INFILE       ASSIGN TO "INSTRUCTORS.TXT"
000900                         ORGANIZATION IS LINE SEQUENTIAL.
001000
001100     SELECT SRTWRK       ASSIGN TO "SRTFILE-INS.WRK".
001200
001300     SELECT OUTFILE      ASSIGN TO "INSTMST.DAT"
001400                         ORGANIZATION  IS INDEXED
001500                         ACCESS        IS SEQUENTIAL
001600                         RECORD KEY    IS OUT-INST-ID
                               ALTERNATE RECORD KEY IS OUT-INST-NAME
                                   WITH DUPLICATES
001700                         FILE STATUS   IS WS-STAT.
001800
      *-----------------------------------------------------------------
001900 DATA DIVISION.
002000 FILE SECTION.
002100 FD  INFILE.
002200 01  IN-REC.
002400     03  IN-INST-NAME    PIC X(20).
002600
002700 SD  SRTWRK.
002800 01  SRT-REC.
003000     03  SRT-INST-NAME   PIC X(20).
003200
003300 FD  OUTFILE.
003400 01  OUT-REC.
           03  OUT-INST-ID     PIC 9(3).
003600     03  OUT-INST-NAME   PIC X(20).
           03  OUT-INST-A      PIC X.
003900
004000 WORKING-STORAGE SECTION.
004100 01  WS-STAT             PIC XX.
       01  WS-INST-ID          PIC 9(3) VALUE ZEROS.
004200 01  WS-EOF              PIC X VALUE 'N'.
004300 SCREEN SECTION.
004400 01  BUILDING-SCRN.
004500     03  BLANK SCREEN.
004600     03  LINE 12 COL 30 VALUE "BUILDING INSTRUCTOR FILE".
004700 01  ERROR-SCRN.
004800     03  BLANK SCREEN.
004900     03  LINE 12 COL 32 VALUE "ERROR BUILDING FILE".
005000     03  LINE 14 COL 32 VALUE "FILE STATUS:".
005100     03          COL 46 PIC XX FROM WS-STAT.
005200     03  LINE 15 COL 32 VALUE "RECORD KEY:".
005300     03          COL 48 PIC X(20) FROM SRT-INST-NAME.
005400     03  LINE 19 COL 32 VALUE "PROGRAM TERMINATED".
005500
005600*-----------------------------------------------------------------
005700 PROCEDURE DIVISION.
005800 100-MAIN.
005900     OPEN OUTPUT OUTFILE.
006000     DISPLAY BUILDING-SCRN
006100     SORT SRTWRK ON ASCENDING KEY SRT-INST-NAME
006200                 USING INFILE
006300                 OUTPUT PROCEDURE 200-CREATE-OUTPUT.
006400     CLOSE OUTFILE.
006500     EXIT PROGRAM.
006600
006700 200-CREATE-OUTPUT.
006800     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
006900     PERFORM 300-LOOP UNTIL WS-EOF = 'Y'.
007000
007100 300-LOOP.
           ADD 1              TO WS-INST-ID.
           MOVE WS-INST-ID    TO OUT-INST-ID.
007300     MOVE SRT-INST-NAME TO OUT-INST-NAME.
           MOVE 'Y'           TO OUT-INST-A.
007600     WRITE OUT-REC
007700         INVALID KEY DISPLAY ERROR-SCRN
007800         STOP RUN
007900     END-WRITE.
008000     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
